﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

public partial class ReportPages_AlphabeticalListOfProductsReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
    }

    private int _yearNum = 1997;
    private bool _showDetails = true;

    private void setReportParameters()
    {
        if (!string.IsNullOrEmpty(yearNumTextBox.Text))
                   _yearNum = Int32.Parse(yearNumTextBox.Text);
        _showDetails = showDetailsCheckBox.Checked;

        LocalReport report = this.ReportViewer1.LocalReport;
        ReportParameterInfoCollection parametersInfo = report.GetParameters();

        ReportParameterInfo yearNumParamInfo = parametersInfo[0];
        ReportParameterInfo showDetailsParamInfo = parametersInfo[1];

        ReportParameter yearNumParameter = new ReportParameter();
        yearNumParameter.Name = "yearNum";
        yearNumParameter.Values.Add(_yearNum.ToString());
        ReportParameter showDetailsParameter = new ReportParameter();
        showDetailsParameter.Name = "doNotShowDetails";
        showDetailsParameter.Values.Add((!_showDetails).ToString());

        report.SetParameters(new ReportParameter[] { yearNumParameter, showDetailsParameter });
    }

    private void refreshReport()
    {
        setReportParameters();
        this.ReportViewer1.LocalReport.Refresh();
    }

    protected void showDetailsCheckBox_CheckedChanged1(object sender, EventArgs e)
    {
        refreshReport();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(yearNumTextBox.Text)) return;
        bool ret = Int32.TryParse(yearNumTextBox.Text, out _yearNum);
        if (!ret) return;
        refreshReport();
    }

}
